余烬缀记

Windows terminal char encoding and proxy settings

edited on:

wallhaven-zm9wxg.jpg

# 字符编码设置

控制面板 => 控制面板\时钟和区域 => 管理 => 非 Unicode 程序的语言

image-20191027184650896

image-20191027184830268

# 终端网络代理

更快捷且临时的方式

$proxy="http://127.0.0.1:10000"
$ENV:HTTP_PROXY=$proxy
$ENV:HTTPS_PROXY=$proxy

在开发时需要使用终端下载各种包,很多时候都是下载慢或者直接超时(感觉没啥变化,该慢的还是慢),所以需要给终端设置代理(终端请求和浏览器请求等不通用)

  • CMD

    设置

    set ALL_PROXY=socks5:127.0.0.1:1080
    # 具体端口号和IP地址以及协议查看本机
    

    取消

    set ALL_PROXY=
    
  • PowerShell

    没找到直接的命令,所以在网上抄了一个脚本,执行后需重启终端

    # NOTE: registry keys for IE 8, may vary for other versions
    # Main menu, allowing user selection
    # menu via https://www.reddit.com/r/PowerShell/comments/9plt0b/easy_tool_menu/
    function Show-Menu
    {
         param (
               [string]$Title = '代理设置工具'
         )
         Clear-Host
         Write-Host "================ $Title ================"
      
         Write-Host "1: 输入 '1' 设置代理."
         Write-Host "2: 输入 '2' 清除代理."    
         Write-Host "Q: 输入 'Q' 退出."
    }
      
    #Functions go here
      
    $regPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'
      
    function Clear-Proxy
    {
        Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 0
        Set-ItemProperty -Path $regPath -Name ProxyServer -Value ''
        Set-ItemProperty -Path $regPath -Name ProxyOverride -Value ''
      
        [Environment]::SetEnvironmentVariable('all_proxy', $null, 'User')
    #     [Environment]::SetEnvironmentVariable('https_proxy', $null, 'User')
    }
      
    function Set-Proxy
    {
    		# 你的代理地址
        $proxy = 'socks5://127.0.0.1:1080'
      
        Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 1
        Set-ItemProperty -Path $regPath -Name ProxyServer -Value $proxy
        Set-ItemProperty -Path $regPath -Name ProxyOverride -Value '<local>'
      
        [Environment]::SetEnvironmentVariable('all_proxy', $proxy, 'User')
    }
      
    #Main menu loop
    do
    {
         Show-Menu
         $input = Read-Host "请输入选择"
         switch ($input)
         {
               '1' {
                    Set-Proxy
                    Write-Host "设置代理成功"
                    return
               } '2' {
                    Clear-Proxy
                    Write-Host "清除代理成功"
                    return
               } 'q' {
                    return
               }
         }
         pause
    }
    until ($input -eq 'q')
    

代理设置成功与否可以使用命令:

curl ip.gs

上面会给出 IP 的信息

如果使用pac模式可以为名单中添加 yarn 和 npm 的源

registry.yarnpkg.com
registry.npmjs.org